<template>
	<view>
		<view class="user-pannel">
			<view class="avatar">
				<u-avatar :src="src" mode="circle" size="160"></u-avatar>
				<text class="account">账户:{{username}}</text>
			</view>
			<view class="set">
				<navigator url="/pages/user-detail/user-detail" class="set-item">
					<text>个人信息</text>
					<u-icon name="arrow-right"></u-icon>
				</navigator>
				<navigator url="/pages/password/password" class="set-item">
					<text>修改密码</text>
					<u-icon name="arrow-right"></u-icon>
				</navigator>
				<navigator url="/pages/order-list/order-list" class="set-item">
					<text>订单列表</text>
					<u-icon name="arrow-right"></u-icon>
				</navigator>
				<navigator url="/pages/feedback/feedback" class="set-item">
					<text>意见反馈</text>
					<u-icon name="arrow-right"></u-icon>
				</navigator>
			</view>
		</view>
		<button @click="submit">退出登录</button>
		<u-modal v-model="show" :content="content" :title="title" :show-cancel-button="true" @confirm="confirm"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: '',
				username: '',
				content: '确定要退出吗',
				show: false,
				title: '友情提示'
			};
		},
		onLoad() {
			this.getData()
		},
		methods: {
			getData(){
				uni.request({
					url:this.$baseurl + '/prod-api/api/common/user/getInfo',
					header: {Authorization: uni.getStorageSync('token')},
					success: (res) => {
						console.log(res.data)
						this.username = res.data.user.nickName
						console.log(this.username)
					}
				})
			},
			submit(){
				this.show = true
			},
			confirm(){
				uni.request({
					url:this.$baseurl + 'logout',
					method: 'POST',
					header: {Authorization: uni.getStorageSync('token')},
					success: (res) => {
						console.log(res.data)
						uni.navigateTo({
							url:'/pages/login/login'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #F7F7F7;
		view{
			padding: 20rpx;
			.user-pannel{
				background-color: #fff;
				.avatar{
					text-align: center;
					display: flex;
					flex-direction: column;
					align-items: center;
				}
				.set{
					display: flex;
					flex-direction: column;
					.set-item{
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						padding: 20rpx;
						align-items: center;
						font-size: 33rpx;
					}
				}
			}
			button{
				background-color: #fa3534;
				color: #fff;
				margin-top: 40rpx;
			}
		}
	}
</style>
